<?php
class counter{
	private $url = "http://www.dantiv.com/piwik/index.php?module=API&method=VisitsSummary.getActions&idSite=1&period=range&date=2011-07-08,{DATENOW}&format=json&token_auth=cc7b82436c4ba7facb4dbbb5a5283a87";
	private $cnt = 0;
	public function __construct(){
		$this->url = str_replace("{DATENOW}",date('Y-m-d'),$this->url);
		$this->cnt = json_decode(file_get_contents($this->url),true);
		$this->cnt = $this->cnt['value'];
	}
	
	public function render(){
		header("Content-type: image/png");
		$im = imagecreatetruecolor(78, 20);
		$index = imagecolorexact($im, 255, 255, 255);
		$grey = imagecolorallocate($im, 128, 128, 128);
		$black = imagecolorallocate($im, 128, 128, 255);
		imagefilledrectangle($im, 0, 0, 78, 20, $index);
		imagecolortransparent($im, $index);
		
		imagerectangle ( $im , 0 , 0 , 77 , 19 , $grey );
		
		// The text to draw
		$text = sprintf("%08d", $this->cnt);
		
		// Replace path by your own font path
		$font = 'arial.ttf';
		
		// Add some shadow to the text
		imagettftext($im, 12, 0, 3, 16, $grey, $font, $text);

		// Add the text
		imagettftext($im, 12, 0, 3, 15, $black, $font, $text);
		
		imagepng($im);
	}
}
$_counter = new counter();
$_counter->render();
?>